package com.ymatou.iapi.idcardmng.testcase;

import java.io.File;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.idcardmng.service.UploadIdCardCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
/**
*上传身份证原图接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UploadIdCard {
	private static UploadIdCardCall uploadidcardCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("上传身份证原图接口");
	}

	@Before
	public void caseUp() {
		uploadidcardCall = new UploadIdCardCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(uploadidcardCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UploadIdCard_001() {
		Logger.start(true, "上传身份证原图成功");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "idCardOpposite .jpg";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("200", uploadidcardCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals(true,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("SourcePicUrl"),
					"验证SourcePicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkPicUrl"),
					"验证MarkPicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkThumbnailUrl"),
					"验证MarkThumbnailUrl非空");

			Logger.verifyIsNull(
					uploadidcardCall.getData().getString("ThumbnailUrl"),
					"验证ThumbnailUrl空");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_002() {
		Logger.start(true, "上传的图片文件小于1KB");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "small.jpg";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("200", uploadidcardCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals(true,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("SourcePicUrl"),
					"验证SourcePicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkPicUrl"),
					"验证MarkPicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkThumbnailUrl"),
					"验证MarkThumbnailUrl非空");

			Logger.verifyIsNull(
					uploadidcardCall.getData().getString("ThumbnailUrl"),
					"验证ThumbnailUrl空");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_003() {
		Logger.start(true, "上传的图片文件大于10MB");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "big.jpg";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("500", uploadidcardCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals("199", uploadidcardCall.getString("BCode"),
					"验证BCode");

			Logger.verifyEquals("图片上传失败！", uploadidcardCall.getString("Msg"),
					"验证Msg");

			Logger.verifyEquals(false,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_004() {
		Logger.start(true, "上传的文件为非图片eg.txt文本文件");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "noteid.txt";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("500", uploadidcardCall.getString("Code"),
					"验证Code");
			Logger.verifyEquals("199", uploadidcardCall.getString("BCode"),
					"验证BCode");

			Logger.verifyEquals("图片上传失败！", uploadidcardCall.getString("Msg"),
					"验证Msg");

			Logger.verifyEquals(false,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_005() {
		Logger.start(true, "修改文本txt文件后綴名為jpg");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "noteid.jpg";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("500", uploadidcardCall.getString("Code"),
					"验证Code");
			Logger.verifyEquals("199", uploadidcardCall.getString("BCode"),
					"验证BCode");

			Logger.verifyEquals("图片上传失败！", uploadidcardCall.getString("Msg"),
					"验证Msg");

			Logger.verifyEquals(false,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_006() {
		Logger.start(true, "图片的文件后缀名为null");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "upload";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("500", uploadidcardCall.getString("Code"),
					"验证Code");
			Logger.verifyEquals("199", uploadidcardCall.getString("BCode"),
					"验证BCode");

			Logger.verifyEquals("图片上传失败！", uploadidcardCall.getString("Msg"),
					"验证Msg");

			Logger.verifyEquals(false,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_007() {
		Logger.start(true, "上传的图片文件为其它格式eg.png");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "upload.jpg";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("200", uploadidcardCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals(true,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("SourcePicUrl"),
					"验证SourcePicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkPicUrl"),
					"验证MarkPicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkThumbnailUrl"),
					"验证MarkThumbnailUrl非空");

			Logger.verifyIsNull(
					uploadidcardCall.getData().getString("ThumbnailUrl"),
					"验证ThumbnailUrl空");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UploadIdCard_008() {
		Logger.start(true, "模拟图片服务超时未响应");
		try {

			String fliename = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "idCard.jpg";
			Logger.comment("添加上传文件:" + fliename);

			uploadidcardCall.addPart("file", fliename);

			uploadidcardCall.callService();

			Logger.verifyEquals("200", uploadidcardCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals("200", uploadidcardCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals(true,
					uploadidcardCall.getData().getBoolean("IsSuccess"),
					"验证IsSuccess");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("SourcePicUrl"),
					"验证SourcePicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkPicUrl"),
					"验证MarkPicUrl非空");
			Logger.verifyNotNull(
					uploadidcardCall.getData().getString("MarkThumbnailUrl"),
					"验证MarkThumbnailUrl非空");

			Logger.verifyIsNull(
					uploadidcardCall.getData().getString("ThumbnailUrl"),
					"验证ThumbnailUrl空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}